import { RichText } from '@tarojs/components';
import EmptyContent from '../EmptyContent';
import './index.less';

export default function ({ content }) {
  if (!content) return <EmptyContent title="暂无商品介绍" />;
  let info = content
    .replace(/<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/gi, '<p')
    .replace(/<p([\s\w"=\/\.:;]+)((?:(class="[^"]+")))/gi, '<p')
    .replace(/<p>/gi, '<p class="p_class" style="text-align: left;font-size: 12rpx;">')
    .replace(/<img([\s\w"-=\/\.:;]+)((?:(height="[^"]+")))/gi, '<img$1')
    .replace(/<img([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/gi, '<img$1')
    .replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/gi, '<img$1')
    .replace(/<img([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/gi, '<img$1');
  info = info.replace(/<img /g, '<img style="max-width:100%;height:auto;margin: 10px auto;" ');

  return <RichText nodes={info} />;
}
